import request from '@/utils/request'
// import qs from 'qs'

// 配置管理

// 上传文件
export function backupUpload (params) {
  var data = fromData(params)
  return request({
    url: '/backup/upload',
    method: 'post',
    data
  })
}

// 下载
export function backupDownload (params) {
  var data = fromData(params)
  return request({
    url: '/backup/download',
    method: 'post',
    responseType: 'blob',
    data
  })
}

// 删除
export function backupDelInfo (params) {
  var data = fromData(params)
  return request({
    url: '/backup/del_info',
    method: 'post',
    data
  })
}

// 备份配置
export function backupConfig (params) {
  var data = fromData(params)
  return request({
    url: '/backup/backupConfig',
    method: 'post',
    data
  })
}

// 恢复出厂设置
export function backupReSet (params) {
  var data = fromData(params)
  return request({
    url: '/backup/reSet',
    method: 'post',
    data
  })
}

// 恢复配置
export function recoveryBackup (params) {
  var data = fromData(params)
  return request({
    url: '/backup/recoveryBackup',
    method: 'post',
    data
  })
}

// 获取备份配置数组
export function getBackupArray (params) {
  var data = fromData(params)
  return request({
    url: '/backup/getBackupArray',
    method: 'post',
    data
  })
}

// 还原
export function backupReduction (params) {
  var data = fromData(params)
  return request({
    url: '/backup/reduction',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
